package com.snail.poker.uitls;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * properties文件配置的读取类
 * 
 * @author Administrator
 * 
 */
public class PropertyReader {
	private static Log log = LogFactory.getLog(PropertyReader.class);

	// TODO PropertyReader devMode
	public static boolean devMode = false;

	private static String property_file = "config.properties";

	private static Properties property = new Properties();

	static {
		InputStream ras = Thread.currentThread().getContextClassLoader()
				.getResourceAsStream(property_file);
		try {
			property.load(ras);

			log.info("load system configuration file: " + property_file);

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				ras.close();
			} catch (IOException e) {
			}
		}
	}

	/**
	 * 获取配置信息
	 * 
	 * @param name
	 * @return
	 */
	public static String get(String name) {
		if (devMode)
			reload();
		return property.getProperty(name);
	}

	/**
	 * 重新载入配置文件
	 */
	private static void reload() {
		InputStream ras = Thread.currentThread().getContextClassLoader()
				.getResourceAsStream(property_file);
		try {
			property.load(ras);
			log.debug("reload property");
		} catch (IOException e) {
		} finally {
			try {
				ras.close();
			} catch (IOException e) {
			}
		}
	}
}